/**
 * 
 */
package com.hexacta.hrs.repositories.impl;

import java.util.Collection;

import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;

import com.hexacta.hrs.familiarrelationship.FamiliarRelationship;

/**
 * @author mfunes
 *
 */
public class FamiliarRelationshipRecordObjectRepository extends	HibernateRecordObjectRepository<FamiliarRelationship> {

	public FamiliarRelationshipRecordObjectRepository(Class<FamiliarRelationship> entityClass) {
		super(entityClass);
	}
	
	/** {@inheritDoc} */
	@SuppressWarnings("unchecked")
	@Override
	public Collection<FamiliarRelationship> matching(FamiliarRelationship criteria) {
		if(criteria.getEmployee()==null)
			return super.matching(criteria);
		Example exampleFamiliarRelationship = Example.create(criteria).ignoreCase().enableLike(MatchMode.ANYWHERE);
		Example exampleEmployee = Example.create(criteria.getEmployee()).ignoreCase().enableLike(MatchMode.ANYWHERE);		
    	return  getSession().createCriteria(FamiliarRelationship.class).add(exampleFamiliarRelationship).createCriteria("employee").add(exampleEmployee).list();
	}


}
